---@class Battle.RayEffect :Battle.EffectBase
local RayEffect = Battle.CreateClass("RayEffect",Battle.EffectBase)
Battle.RayEffect = RayEffect

---@param bullet Battle.Bullet
function RayEffect:BindBullet(bullet)
    self.bindId = bullet.id
    self.endPos = Vector3.New()
    Battle.GlobalEventSystem.Register(Battle.Event.BulletPosChanged,self.BulletUpdatePos,self)
    Battle.GlobalEventSystem.Register(Battle.Event.BulletDie,self.BulletDie,self)
end
---@param args BulletArgs
function RayEffect:BulletUpdatePos(args)
    if args.bullet.id ~= self.bindId then return end
    self.endPos:SetV(args.bullet.pos)
    self:UpdateRay()
end
---@param args BulletArgs
function RayEffect:BulletDie(args)
    if args.bullet.id ~= self.bindId then return end
    Battle.GlobalEventSystem.UnRegister(Battle.Event.BulletPosChanged,self.UpdatePos,self)
    Battle.GlobalEventSystem.UnRegister(Battle.Event.BulletDie,self.Die,self)
    self.during = 0.5
end
function RayEffect:OnLoadFinished()
    ---@type CRayEffect
    self.cRay = self.obj:GetComponent(typeof(CRayEffect))
    if self.cRay == nil then
        logError(self.resName.."特效没有绑定CRayEffect脚本")
        return
    end
    self:UpdateRay()
end
function RayEffect:UpdateRay()
    if not self.cRay then return end
    self.cRay:Set(self.pos.x,self.pos.y,self.pos.z,self.endPos.x,self.endPos.y,self.endPos.z)
end